
/**
 * Copyright 2009 cestum.org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
package org.waveprotocol.wave.model.document.operation.util {
import org.waveprotocol.wave.model.util.Preconditions;

  /**
   * A name-value pair representing an attribute.
   */
public final class Attribute {
    // TODO: This class can be simplified greatly if
    // AbstractMap.SimpleImmutableEntry from Java 6 can be used.

    var name:String;
    var value:String;

//    /**
//     * Creates an attribute with a map entry representing an attribute
//     * name-value pair.
//     *
//     * @param entry The attribute's name-value pair.
//     */
//    public Attribute(Map.Entry<String,String> entry) {
//      this(entry.getKey(), entry.getValue());
//    }

    /**
     * Creates an attribute given a name-value pair.
     *
     * @param name The name of the attribute.
     * @param value The value of the attribute.
     */
    public function Attribute(name:String, value:String) {
      Preconditions.checkNotNull(name, "Null attribute name");
      Preconditions.checkNotNull(value, "Null attribute value");
      this.name = name;
      this.value = value;
    }

    
    public function getKey():String {
      return name;
    }

    
    public function getValue():String {
      return value;
    }

    
    public function setValue(value:String):String {
      throw new Error("Attempt to modify an immutable map entry.");
    }

    
//    public function equals(o:Object):Boolean {
//      if (!(o instanceof Map.Entry)) {
//        return false;
//      }
//      Map.Entry<?,?> entry = (Map.Entry<?,?>) o;
//      return ((name == null) ? entry.getKey() == null : name.equals(entry.getKey())) &&
//          ((value == null) ? entry.getValue() == null : value.equals(entry.getValue()));
//    }
//
//    
//    public function hashCode():int {
//      return ((name == null) ? 0: name.hashCode()) ^
//          ((value == null) ? 0: value.hashCode());
//    }

    
    public function toString():String {
      return "Attribute(" + name + "=" + value + ")";
    }
  }
}